<template>
    <div class="">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i>&nbsp;编辑设备分类</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        
        <div class="container">
            <el-form ref="form" label-width="120px">
                
                <el-form-item label="设备分类：">
                    <el-input v-model="title" placeholder="请输入设备分类" style="width:400px"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submit">确认发布</el-button>
                </el-form-item>
            </el-form>
        </div>
        
    </div>
</template>
<script>
import {deviceCategoryQuery,deviceCategoryEdit} from '@/api/device';
export default {
    name:"deviceCategoryEdit",
    data() {
        return {
            typeId:'', //当前要删除图片的类型   1封面图 2详情图  3关键词
            idx:0,//当前记录的下标
            delVisible:false,
            fullscreenLoading:false,
            delVisible:false,
            title:'',//分类
            id:'',//分类id
        }
    },
    components: {

    },
    //实例创建
    created(){
        if(this.$route.query.id &&this.$route.query.id!=""){
            this.id = this.$route.query.id;
            this.getDetails();
        }
    },
    //计算属性
    computed:{
		
    },
    //方法
    methods: {
    	
    	//查询详情
    	getDetails(){
    		var param = {
				pageIndex:1,
				pageSize:999
        	}
        	deviceCategoryQuery(param).then((response) => {
                if(response.code==200){
                    var data = response.data.list;//当前返回的数据
                    var id = this.id;
                    var title ='';
					$.each(data, function(index,val) {
						if(val.id == id){
							title = val.name
						}
					});	
					this.title = title;
                }else{
                    this.$notify.error({
                        title: '异常',
                        offset: 100,
                        message: response.msg
                    });
                }
        	})
    	},
    	
        //确认发布
        submit(){
// console.log(this.$refs.vueWangeditor.getText().length);
            if(this.title==""){
                this.$notify.info({title: '提示',message: '请输入设备分类名称'});
                return false;
            }
            else{
                let param ={}
                param.id=this.id;
                param.title=this.title;
                this.saveGoods(param);
            }
        },
        //提交信息上传
        saveGoods(param){
            var _this =this;
            deviceCategoryEdit(param).then(response=>{
                // console.log(response);
                if(response.code==200){
                    this.$message({
                        message: '恭喜你，发布成功',
                        type: 'success'
                    });
                    setTimeout(function(){
                         _this.$router.push('/device/category');
                    },1500);

                }else{
                    this.$notify.error({
                        title: '发布失败',
                        duration:2000,
                        message: '失败原因：'+response.msg
                    });
                }
            }).catch(error=>{
                console.log(error);
            });
        },
    }
}
</script>
<style>
    
</style>


